package com.computerManagementSystem.mapper;

import com.computerManagementSystem.pojo.BorrowThing;
import com.computerManagementSystem.pojo.Things;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author 赖志宇
 * @date 2020/6/26 23:21
 */
@Mapper
public interface ThingMapper {

    void insertBorrowThingForm(BorrowThing borrowThing);

    @Update("update borrow_things set state = '已归还',end_date = now() where tid=#{tid} and id = #{id} and start_date=#{startDate};")
    void updateBorrowThingForm(BorrowThing borrowThing);

    @Select("select tid,things.name as itemName,amount,start_date as startDate from borrow_things left join things using(tid) where id = #{id} and state = '未归还'")
    List<BorrowThing> getBorrowingThingListById(String id);

    @Select("select tid,things.name as itemName,personal_information.name as memberName,amount,start_date as startDate,end_date as endDate from borrow_things left join things using(tid) left join personal_information using(id) limit #{start},#{limit}")
    List<BorrowThing> getBorrowThingList(@Param(value = "start") int start,@Param(value = "limit") int limit);

    void insertThingForm(Things things);

    void updateThingForm(Things things);

    @Select("select * from things limit #{start},#{limit}")
    List<Things> getThingsList(@Param(value = "start") int start,@Param(value = "limit") int limit);

    @Select("select * from things where current_amount>0 limit #{start},#{limit}")
    List<Things> getThingsListCanBorrow(@Param(value = "start") int start,@Param(value = "limit") int limit);

    @Select("select count(*) from borrow_things ")
    int queryBorrowThingNum();

    @Select("select count(*) from things ")
    int queryThingNum();

    @Select("select count(*) from things where current_amount>0")
    int queryThingCanBorrowNum();

}
